package com.example.algorithm.tree;

import java.util.Date;

/**
 * @author : zhy
 * @since : 2022/8/8
 * 找树左下角的值，也就是最下面一行，最靠近左边的值
 */
public class TreeLeftNodeValue {

    private int Deep=-1;
    private int value=0;
    public int findBottomLeftValue(TreeNode root) {
        value= root.val;
        dfs(root,0);
        return value;
    }

    private void dfs(TreeNode root, int deep) {
        if(root==null) {
            return;
        }
        if(root.left==null&&root.right==null)
        {
            if(deep>Deep){
                value=root.val;
                Deep=deep;
            }
        }
        if(root.left!=null){
            dfs(root.left,deep+1);
        }
        if(root.right!=null){
            dfs(root.right,deep+1);
        }
    }
}
